package com.irun.cm;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;

/***
 * @author huangsm
 * @date 2012-4-12
 * @email huangsanm@gmail.com
 * @desc 发送短信
 */
public class MessageActivity extends ActivityGroup implements OnClickListener {
	
	private static final String MANAGER_MESSAGE_TAB = "manager_message";
	private static final String WRITE_MESSAGE_TAB = "write_message";

	private LinearLayout container;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitle(R.string.message);
		setContentView(R.layout.message);
		container = (LinearLayout) findViewById(R.id.container);
		
		ImageView message_iv = (ImageView) findViewById(R.id.message_list);
		message_iv.setOnClickListener(this);
		
		ImageView write_iv = (ImageView) findViewById(R.id.write_message);
		write_iv.setOnClickListener(this);
		
		//初始化Activity到ActivityGroup容器
		initActivity(MANAGER_MESSAGE_TAB);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.message_list:
				initActivity(MANAGER_MESSAGE_TAB);
				break;
			case R.id.write_message:
				initActivity(WRITE_MESSAGE_TAB);
				break;
		}
	}
	
	private void initActivity(String tag){
		View view;
		container.removeAllViews();
		if(tag.equals(MANAGER_MESSAGE_TAB)){
			view = getLocalActivityManager()
					.startActivity(MANAGER_MESSAGE_TAB, 
							new Intent(this, MessageListActivity.class))						
							.getDecorView();
		} else {
			view = getLocalActivityManager()
					.startActivity(WRITE_MESSAGE_TAB, 
							new Intent(this, WriteMessageActivity.class))
					.getDecorView();
		}
		container.addView(view);
	}
}
